package com.shoy.myapp.ui;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.*;
import com.shoy.myapp.R;
import com.shoy.myapp.base.BaseActivity;
import com.shoy.myapp.view.PullScrollView;

/**
 * ��ҳ��
 *
 * @author shay
 * @created 2015/4/4
 */
public class Main extends BaseActivity implements PullScrollView.OnTurnListener {

    @Override
    public int bindLayout() {
        return R.layout.ui_main;
    }

    @Override
    public void initView(View view) {
        PullScrollView mScrollView = (PullScrollView) findViewById(R.id.scroll_view);
        ImageView mHeadImg = (ImageView) findViewById(R.id.background_img);
        TableLayout mMainLayout = (TableLayout) findViewById(R.id.table_layout);
        mScrollView.setHeader(mHeadImg);
        mScrollView.setOnTurnListener(this);
        TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(
                TableRow.LayoutParams.MATCH_PARENT,
                TableRow.LayoutParams.WRAP_CONTENT);
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.leftMargin = 30;
        layoutParams.bottomMargin = 10;
        layoutParams.topMargin = 10;
        for (int i = 0; i < 30; i++) {
            TableRow tableRow = new TableRow(this);
            TextView textView = new TextView(this);
            textView.setText("Test pull down scroll view " + i);
            textView.setTextSize(20);
            textView.setPadding(15, 15, 15, 15);

            tableRow.addView(textView, layoutParams);
            if (i % 2 != 0) {
                tableRow.setBackgroundColor(Color.LTGRAY);
            } else {
                tableRow.setBackgroundColor(Color.WHITE);
            }

            final int n = i;
            tableRow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(Main.this,
                            "Click item " + n, Toast.LENGTH_SHORT).show();
                }
            });
            mMainLayout.addView(tableRow);
        }
    }

    @Override
    public void doBusiness(Context mContext) {

    }

    @Override
    public void onTurn() {

    }
}
